from llm_response.llm_response import ask_llm20_1
from uitls.parse.parse_order import parse_order_ids
from uitls.reqquests_post import get_payment_inquiry_pdf
import telebot
import json
TOKEN = '7702930752:AAGYV0-kGJgMTavSPKxqdgo8tkR_gdthYJI'
bot = telebot.TeleBot(TOKEN)

def payout_correction(country_name_address, message):
    print("代付冲正")
    order_lists = ask_llm20_1(message.text)
    order_list_parse = parse_order_ids(order_lists)
    if order_list_parse['order_ids']:
        print("订单号存在")
        data_payoutOrder = get_payment_inquiry_pdf(country_name_address, order_list_parse['order_ids'][0])
        try:
            parsed = json.loads(data_payoutOrder)  # 先把 JSON 字符串转成字典
            print("data_payoutOrder", parsed)
            if parsed['status'] == 200:
                print("订单存在")
                if parsed['data']['orderInfo']['status'] == 6:
                    print("冲正了")
                    bot.reply_to(message, f'''
                                                    冲正了
                                                    ''')
                else:
                    print("没有冲正")
                    bot.reply_to(message, f'''
                                                    没有冲正
                                                    ''')
            else:
                print("Order not found")
                bot.reply_to(message, f'''
                                                    订单号不存在
                                                    ''')
        except json.JSONDecodeError:
            print("不是 JSON，原始输出：", data_payoutOrder)
            parsed = {"status": 201}  # 先把 JSON 字符串转成字典
